#include "debuguartcommandserver.h"
#include "log/logger.h"


DebugUartCommandServer::DebugUartCommandServer()
{

}

DebugUartCommandServer::~DebugUartCommandServer()
{

}

void DebugUartCommandServer::Attach(IF_SOC_Uart *uart)
{
    if(uart == nullptr)
        return;
    
    Dettach();
    m_uart = uart;
    m_uart->SetDataReceivedCallBack([=](IF_SOC_Uart &sender, uint8_t c){
        FW_UNUSED(sender);
        AddRecvByte(c);
    });
    m_uart->StartReceive_IT();
}

void DebugUartCommandServer::Dettach()
{
    if(m_uart == nullptr)
        return;

    m_uart->SetDataReceivedCallBack(nullptr);
    m_uart = nullptr;
}

bool DebugUartCommandServer::OnWriteStream(const char *str)
{
    //用logdebug，因为里面有lock
    LogDebug().AsRaw().Force()<<str;
    return true;
}
